# 类
class Person:
    # 类加载的时候会执行一次，之后实例化不会再执行
    # print('1')
    # 类的属性
    name = 'jueyi'
    sex = 'male'

    # 构造函数
    def __init__(self, hobby='sing'):
        # 每次实例化的时候都会执行
        # print('2')
        # 实例的属性
        self.hobby = hobby

    # 析构函数
    def __del__(self):
        print('销毁')

    # 实例方法：类中的所有实例方法都必须有self参数
    def say_hello(self):
        print('Hi, I am %s.' % self.name)

    # 类方法：当方法中需要使用类对象（比如访问私有类属性）时，使用类方法
    @classmethod
    def get_name(cls):
        print(cls)
        print('My name is %s.' % cls.name)
        # 类方法中无法访问实例属性
        try:
            print(cls.hobby)
        except Exception as e:
            print(e)


class Dog(object):
    # 静态方法
    @staticmethod
    def run():
        print('Dog is running...')

    @staticmethod
    def eat(name):
        print(f'{name} is eating...')


print(Person.name)
Person.name = 'hhh'
print(Person.name)
Person.age = 18
print(Person.age)

del Person.age
try:
    print(Person.age)
except Exception as e:
    print(e)

# 对象
person1 = Person()
print(person1, type(person1))
person1.age = 18
try:
    print(person1.age)
    print(Person.age)
except Exception as e:
    print(e)

person1.say_hello()
person2 = Person()
person2.name = 'jueyi'
person2.say_hello()

print(person2.hobby)
person3 = Person('jogging')
print(person3.hobby)
try:
    print(Person.hobby)
except Exception as e:
    print(e)

del person1
print('end')

Dog.run()
dog = Dog()
dog.run()

Dog.eat('A')
dog.eat('B')

Person.get_name()
person2.get_name()
